import React from 'react';
import { Row, Col, Form, Input, message, Button } from 'antd';
const R = require('ramda');
const FormItem = Form.Item;


export default Form.create({ wrappedComponentRef: true })(class ExtraInfo extends React.Component {

	constructor(props) {
		super(props);
	}

	handleConfirm = () => {
		this.props.form.validateFields({ force: true }, (errors, values) => {
			if (errors) return;
			let dataSource = this.props.dataSource ? this.props.dataSource : {};
			values.cstId = this.props.cstid;
			values.id = dataSource && dataSource.id ? dataSource.id : undefined;
			this.props.dispatch({
				type: values.id ? 'customerManage/updateCustomerExtra' : 'customerManage/createCustomerExtra',
				payload: {
					...values,
					onSuccess: () => {
						this.props.dispatch({ type: 'customerManage/getCustomerById', payload: { id: this.props.cstid, isApproval: true } });
						if (this.props.handleReUpdateExtra) this.props.handleReUpdateExtra(false);
					}
				}
			})
		});
	}

	handleResetFields = () => {
		this.props.form.resetFields();
		if (this.props.handleReUpdateExtra) this.props.handleReUpdateExtra(false);
	}

	render() {
		const { getFieldDecorator } = this.props.form;
		let dataSource = R.isNil(this.props.dataSource) ? {} : this.props.dataSource;
		let formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
		return (
			<Form>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="发票抬头" hasFeedback>
                            {getFieldDecorator('name', {
                                rules: [{
                                    required: true, message: '请输入发票抬头'
                                }],
                                initialValue: dataSource.name
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="纳税人识别号" hasFeedback>
                            {getFieldDecorator('taxplayercode', {
                                rules: [{
                                    required: true, message: '请输入纳税人识别号'
                                }],
                                initialValue: dataSource.taxplayercode
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="注册场所地址" hasFeedback>
                            {getFieldDecorator('address', {
                                rules: [{
                                    required: true, message: '请输入注册场所地址'
                                }],
                                initialValue: dataSource.address
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem></Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="注册固定电话" hasFeedback>
                            {getFieldDecorator('contacttel', {
                                rules: [{
                                    required: true, message: '请输入注册固定电话'
                                }],
                                initialValue: dataSource.contacttel
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="基本开户银行名称" hasFeedback>
                            {getFieldDecorator('contacttel', {
                                rules: [{
                                    required: true, message: '请输入基本开户银行名称'
                                }],
                                initialValue: dataSource.contacttel
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="基本开户账号" hasFeedback>
                            {getFieldDecorator('contacttel', {
                                rules: [{
                                    required: true, message: '请输入基本开户账号'
                                }],
                                initialValue: dataSource.contacttel
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="开票人财务联系人" hasFeedback>
                            {getFieldDecorator('financialcontactor', {
                                rules: [{
                                    required: false, message: '请输入开票人财务联系人'
                                }],
                                initialValue: dataSource.financialcontactor
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="开票人财务联系电话" hasFeedback>
                            {getFieldDecorator('financialtelephone', {
                                rules: [{
                                    required: false, message: '请输入开票人财务联系电话'
                                }],
                                initialValue: dataSource.financialtelephone
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
				<Row>
					<Col span={24}>
						<FormItem {...formItemLayout} label="说明" hasFeedback>
                            {getFieldDecorator('memo', {
                                rules: [{
                                    required: false, message: '请输入说明'
                                }],
                                initialValue: dataSource.memo
                            })(
								<Input disabled={(this.props.disabled || dataSource.name) && !this.props.extraUpdating} />
                            )}
						</FormItem>
					</Col>
				</Row>
			</Form>
		)
	}
})